<template>
  <div>
    <my-simple-page
      :search-fields="searchFields"
      :tableTitle="tableTitle"
      :columns="columns"
      :search-url="searchUrl"
      :delete-url="deleteUrl">
    </my-simple-page>
  </div>
</template>

<script>
  export default {
    name: "file-index",
    data(){
      return{
        searchFields: [
          {
            type: 'input',
            label: '文件名称',
            prop: 'name'
          }
        ],
        tableTitle: '文件列表',
        columns: [
          {label:'文件名称',prop: 'name',width:'200'},
          {label:'文件大小',prop: 'size',render: this.renderSize},
          {label:'网络路径',prop: 'url'},
          {label:'磁盘路径',prop: 'realPath'},
          {label:'上传时间',prop: 'createTime',width:'200'}
        ],
        searchUrl: '/api/general/file/getFileList',
        deleteUrl: '/api/general/file/getFile',
        statusDict: [],
      }
    },
    methods:{
      renderSize(size){
        if(size > 1000 * 1000 * 1000){
          return Math.round(size * 100 / (1000 * 1000 * 1000)) / 100 + 'GB';
        }else if(size > 1000 * 1000){
          return Math.round(size * 100 / (1000 * 1000)) / 100 + 'MB';
        }else{
          return Math.round(size * 100 / 1000) / 100 + 'KB';
        }
      }
    },
    created(){
      this.$ajax.getDict('PLAN_STATUS_DICT').then(res=>{
        this.statusDict = res;
      });
    }
  }
</script>

<style scoped>

</style>
